/**
 * 下载图片
 * @param {*} blob 图片流对象
 * @param {*} fileName 图片名称，要带后缀
 */
export function downloadImgByBlob(blob, fileName = '') {
    const a = document.createElement('a')
    a.href = window.URL.createObjectURL(blob)
    a.download = fileName
    a.click()
}
/**
 * 下载图片
 * @param {*} urlOrBase64 url或者base64字符串
 * @param {*} fileName 图片名称，要带后缀
 */
export function downloadImgByUrlOrBase64(urlOrBase64, fileName = '') {
    const img = new Image()
    img.src = urlOrBase64
    img.setAttribute('crossOrigin', 'Anonymous')
    img.onload = () => {
        const canvas = document.createElement('canvas')
        const { width, height } = img
        canvas.width = width
        canvas.height = height
        const ctx = canvas.getContext('2d')
        ctx.drawImage(img, 0, 0, width, height)
        const a = document.createElement('a')
        a.href = canvas.toDataURL()
        a.download = fileName
        a.click()
    }
}